#pragma once

#include "Types.h"



namespace MemMgr
{
	class Chunk
	{
		friend class FixedSizeAllocator;

		typedef AtomSizeU BlockData;
		typedef AtomSizeU* BlockDataPtr;
		typedef AtomSizeU BlockCounter;

		void Init(const size_t iBlockSize, const BlockCounter iNnumBlocks);
		void* Allocate(const size_t iBlockSize);
		void Deallocate(void* iPtr, const size_t iBlockSize);
		void Release(void);

		inline bool HasBlock(void * iPtr, const size_t iChunkLength) const;
		//inline bool HasAvailableBlock(void) const;
		inline bool HasAvailableBlocks(const size_t iNumBlocks) const;
		inline bool IsFull(void) const;

		static const BlockCounter MAX_NUM_BLOCKS = ~0;

		BlockDataPtr mData;
		BlockCounter mFirstAvailableBlock;
		BlockCounter mNumAvailableBlocks;
	};

	inline bool Chunk::HasBlock(void * iPtr, size_t iChunkLength) const
	{
		return (iPtr >= mData) && (iPtr < mData + iChunkLength);
	}

	//inline bool Chunk::HasAvailableBlock(void) const
	//{
	//	return (mNumAvailableBlocks > 0);
	//}

	inline bool Chunk::HasAvailableBlocks(const size_t iNumBlocks) const
	{
		return (mNumAvailableBlocks >= iNumBlocks);
	}

	inline bool Chunk::IsFull(void) const
	{
		return (0 == mNumAvailableBlocks);
	}


};